package com.guo.redis.business.hello.service;

import java.util.concurrent.TimeUnit;

/**
 * 分布式锁 service 接口定义
 */
public interface IDistributeLockService {

    /**
     * 尝试获取锁1次
     * @param key lock-key
     * @param value lock-value for per thread
     * @param time lock exists time
     * @param timeUnit lock exists time's unit
     * @return true: success; false: failed
     */
    boolean tryLock(String key, String value, long time, TimeUnit timeUnit);

    /**
     * 尝试在timeOut ms 毫秒内获取锁
     * @param key lock-key
     * @param value lock-value for per thread
     * @param time lock exists time
     * @param timeUnit lock exists time's unit
     * @param timeOut true: success; false: failed
     * @return true: success; false: failed
     */
    boolean tryLock(String key, String value, long time, TimeUnit timeUnit, long timeOut);

    /**
     * 尝试 释放锁
     * @param key lock-key
     * @param value lock-value for per thread
     * @return true: success; false: failed
     */
    boolean unlock(String key, String value);
}
